package demo.gui;

import engine.gui.Action;
import engine.gui.GUIStyle;
import engine.gui.elements.Button;
import engine.gui.elements.Checkbox;
import engine.gui.elements.Label;
import engine.gui.elements.Panel;
import engine.gui.elements.RadioButtonGroup;
import engine.gui.elements.ScrollPane;
import engine.gui.elements.Slider;
import engine.gui.elements.TextField;
import engine.gui.popup.Popup;
import engine.scene.Scene;

public class StartScene extends Scene{
	
	public StartScene(String name) {
		super(name);
	}

	@Override
	public void init() {
		setGUIStyle(GUIStyle.getDefaultStyle());
		
		final Panel p = new Panel(10, 10, 550, 400);
		p.setSolid(true);
		p.setAlign(Panel.ALIGN_RIGHT);
		p.setValign(Panel.ALIGN_BOTTOM);
		getWindowManager().addComponent(p);
		
		Label l = new Label("Hallo:", 10, 10, 80, 30);
		p.addComponent(l);
		
		Button b = new Button("Button", 100, 10, 80, 30);
		b.setAction(new Action() {
			@Override
			public void performAction() {
				getWindowManager().addPopup(createPopup());
			}
		});
		p.addComponent(b);
		
		TextField f = new TextField(190, 10, 80, 30);
		p.addComponent(f);
		
		Button b2 = new Button("Switch scene", 280, 10, 120, 30);
		b2.setAction(new Action() {
			@Override
			public void performAction() {
				setCurrentScene("lobby");
			}
		});
		p.addComponent(b2);
		
		final Checkbox c = new Checkbox("A checkbox", 10, 50, 20, 20);
		c.setAction(new Action() {
			@Override
			public void performAction() {
				System.out.println("Check box " + (c.isChecked() ? "enabled" : "disabled"));
			}
		});
		p.addComponent(c);
		
		final RadioButtonGroup r = new RadioButtonGroup(10, 90, 20, 20);
		r.setAction(new Action() {
			@Override
			public void performAction() {
				System.out.println("selected index of radio button group: " + r.getSelectedIndex());
			}
		});
		r.addEntry("Entry 1");
		r.addEntry("Entry 2");
		p.addComponent(r);
		
		final Label label = new Label(10, 165, 100, 20);
		p.addComponent(label);
		
		final Slider slider = new Slider(10, 140, 150, 20);
		slider.setMinValue(0);
		slider.setMaxValue(10);
		slider.setAction(new Action() {
			@Override
			public void performAction() {
				label.setText(slider.getCurrentValue() + "");
			}
		});
		p.addComponent(slider);
		
		ScrollPane scrollPane = new ScrollPane(200, 100, 200, 200);
		scrollPane.setSolid(true);
		p.addComponent(scrollPane);
	}
	
	private Popup createPopup() {
		final Popup popup = new Popup((int)(Math.random() * getWindowManager().getWidth()), (int)(Math.random() * getWindowManager().getHeight()), 100, 100);
		
		Label l = new Label("Test", 5, 5, 50, 20);
		popup.addComponent(l);
		
		Button btn = new Button("Click", 5, 30, 50, 30);
		btn.setAction(new Action() {
			@Override
			public void performAction() {
				popup.dispose();
			}
		});
		popup.addComponent(btn);
		
		return popup;
	}
}
